package com.chatai.repository;

import com.chatai.model.ChatRoom;
import com.chatai.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface ChatRoomRepository extends JpaRepository<ChatRoom, Long> {
    // 根据创建者查找聊天室
    List<ChatRoom> findByCreator(User creator);
    
    // 根据成员查找聊天室
    List<ChatRoom> findByMembersContaining(User user);
    
    // 查找用户参与的群聊
    List<ChatRoom> findByMembersContainingAndRoomType(User user, String roomType);
    
    // 查找两个用户之间的私聊
    Optional<ChatRoom> findByRoomTypeAndMembersContainingAndMembersContaining(String roomType, User user1, User user2);
}